#!/bin/sh -e

start() {
	echo
	echo "----------------- Starting the miniServerRuby ----------------"
	ruby /root/Server/miniServerRuby.rb start
	ruby /root/Server/miniServerRuby.rb status
	echo
}

stop() {
	echo
	echo "----------------- Stop the miniServerRuby ----------------"
	ruby /root/Server/miniServerRuby.rb stop
	ruby /root/Server/miniServerRuby.rb status
	echo
}

restart(){
	echo
	echo "----------------- Restart the miniServerRuby ----------------"
	ruby /root/Server/miniServerRuby.rb restart
	ruby /root/Server/miniServerRuby.rb status
	echo
}

run(){
	echo
	echo "----------------- Run the miniServerRuby ----------------"
	ruby /root/Server/miniServerRuby.rb run
	echo
}

status(){
	echo
	echo "----------------- Status of the miniServerRuby ----------------"
	ruby /root/Server/miniServerRuby.rb status
	echo
}

case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	restart)
		restart
		;;
	status)
		status
		;;
	run)
		run
		;;
	*)
		echo	
		echo "Usage: miniServerRuby.sh <command>"
		echo 
		echo "* where <command> is one of:"
		echo
		echo "  start         start an instance of the application"
		echo "  stop          stop the instance of the application"
		echo "  restart       stop the instance and restart them afterwards"
		echo "  run           start the application and stay on top"
		echo "  status        show status (PID) of application instance"
		echo 
		exit 1
		;;
esac
exit $?
